import { createRouter, createWebHashHistory } from 'vue-router'

// import Layout from '@/views/Layout/index.vue'
// 按需导入 被访问才会加载
const Layout = () => import('@/views/Layout')
// import Home from '@/views/Home/index.vue'
// 按需导入
const Test = () => import('@/test/index.vue')
const Home = () => import('@/views/Home')
const Category = () => import('@/views/Category')
const CategorySub = () => import('@/views/Category/sub.vue')
const Goods = () => import('@/views/Goods/index.vue')
const Login = () => import('@/views/Login/index.vue')
const Callback = () => import('@/views/Login/callback.vue')
const routes = [
  {
    path: '/',
    component: Layout,
    children: [{
      path: '/',
      component: Home
    },
    // 一级分类页面
    {
      path: '/category/:id',
      component: Category
    },
    // 二级分类页面
    {
      path: '/category/sub/:id',
      component: CategorySub
    },
    // 商品详情
    {
      path: '/goods/:id',
      component: Goods
    }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  // {
  //   path: '/',
  //   component: Login
  // }
  {
    path: '/login/callback',
    component: Callback
  },
  {
    path: '/test',
    component: Test
  }

]

const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则，写法和之前一样
  routes,
  // 路由切换会挺流弊在上个页面的位置问题
  // v2
  // scrollBehavior:()=>({y:0})
  // v3
  scrollBehavior () {
    return { top: 0, left: 0 }
  }

})

export default router
